<template>
    <el-form :model="ruleForm2" :rules="rules2" ref="ruleForm2" label-position="left" label-width="0px" class="demo-ruleForm login-container">
        <h3 class="title">找回密码</h3>
        <el-form-item prop="account">
            <el-input type="text" v-model="ruleForm2.account" auto-complete="off" placeholder="账号"></el-input>
        </el-form-item>
        <el-form-item prop="newPass">
            <el-input type="password" v-model="ruleForm2.newPass" auto-complete="off" placeholder="新密码"></el-input>
        </el-form-item>
        <!-- <div class="password-flex">
            <el-checkbox v-model="checked" checked class="remember">记住密码</el-checkbox>
            <a class="forget" href="">忘记密码?</a>
        </div> -->
        <div class="btn-flex">
            <el-form-item style="width:45%;">
                <el-button type="primary" style="width:100%;" @click.native="loginClick(ruleForm2)" :loading="logining">确定</el-button>

            </el-form-item>
            <el-form-item style="width:45%;">

                <el-button type="primary" style="width:100%;" @click.native="goBack">返回</el-button>
            </el-form-item>
        </div>
    </el-form>
</template>

<script>
import utils from "../../util/request.js";
export default {
    data() {
        return {
            logining: false,
            ruleForm2: {
                account: "", //账号
                newPass: "" //新密码
            },
            rules2: {
                account: [
                    { required: true, message: "请输入账号", trigger: "blur" }
                ],
                newPass: [
                    { required: true, message: "请输入新密码", trigger: "blur" }
                ]
            },
            checked: true
        };
    },
    methods: {
        goBack() {
            // 返回
            this.$router.go(-1);
        },
        loginClick() {
            let that = this;
            that.$refs.ruleForm2.validate(valid => {
                if (valid) {
                    that.logining = true;
                    request
                        .request(
                            "user/password?username=" +
                                that.ruleForm2.account +
                                "&newPassword=" +
                                that.ruleForm2.newPass +
                                "&type=" +
                                1 +
                                "&userid=" +
                                localStorage.setUserid,
                            "put"
                        )
                        .then(res => {
                            console.log(res);
                            that.logining = false;

                            if (res.data.code == 20000) {
                                that.$message({
                                    type: "success",
                                    message: "修改成功，请重新登录！"
                                });
                                setTimeout(function() {
                                    that.$router.go(-1);
                                }, 1000);
                            }
                            if (res.data.code == 20005) {
                                that.$message({
                                    type: "error",
                                    message: res.data.msg + ",请重新输入！"
                                });
                                that.ruleForm2.account = "";
                            }
                        });
                } else {
                    console.log("error submit!!");
                    return false;
                }
            });
        }
    },
    created() {}
};
</script>

<style lang="scss" scoped>
.login-container {
    /*box-shadow: 0 0px 8px 0 rgba(0, 0, 0, 0.06), 0 1px 0px 0 rgba(0, 0, 0, 0.02);*/
    -webkit-border-radius: 5px;
    border-radius: 5px;
    -moz-border-radius: 5px;
    background-clip: padding-box;
    margin: 180px auto;
    width: 350px;
    padding: 35px 35px 15px 35px;
    background: #fff;
    border: 1px solid #eaeaea;
    box-shadow: 0 0 25px #cac6c6;
    .title {
        margin: 0px auto 40px auto;
        text-align: center;
        color: #505458;
    }
    .btn-flex {
        display: flex;
        align-items: center;
        justify-content: space-between;
    }
    .remember {
        margin: 0px 0px 20px 0px;
    }
}
</style>